var mobId, mob, stats, modified, MaxRandom, setupTask, ostats, victor, luck;
var 清怪 = true;
var 刷新地图 = false;
var 复活次数 = 11;
var 副本名称 = "扎昆[普通]";
var BOSS_1_id = 8800002;
var BOSS_1_血量倍率 = 1;
var BOSS_2_id = 8800003;
var BOSS_2_血量倍率 = 1;
var BOSS_3_id = 8800004;
var BOSS_3_血量倍率 = 1;
var BOSS_4_id = 8800005;
var BOSS_4_血量倍率 = 1;
var BOSS_5_id = 8800006;
var BOSS_5_血量倍率 = 1;
var BOSS_6_id = 8800007;
var BOSS_6_血量倍率 = 1;
var BOSS_7_id = 8800008;
var BOSS_7_血量倍率 = 1;
var BOSS_8_id = 8800009;
var BOSS_8_血量倍率 = 1;
var BOSS_9_id = 8800010;
var BOSS_9_血量倍率 = 1;
var 副本时限 = 1000 * 60 * 20;
var 实例地图 = [280030100];
var 准备地图 = 211042300;
var 退场倒计时 = 180;

function init() {}

function setup(e, a) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var c = em.newInstance(副本名称);
    for (var b = 0; b < 实例地图.length; b++) {
        var d = c.setInstanceMap(实例地图[b]);
        d.resetPQ(e);
        d.resetFully();
        d.killAllMonsters(清怪);
        d.respawn(刷新地图)
    }
    c.startEventTimer(副本时限);
    c.setProperty("FBtime", 副本时限);
    c.setProperty("FBname", 副本名称);
    c.setProperty("strMap", 准备地图);
    em.schedule("台阶可见", 10 * 1000);
    return c
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(c, b, a) {
    if (实例地图.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 实例地图[0]:
            initProp("stage" + 1 + "_kill", 0);
            break
    }
}

function onMonsterKilled(a, b) {
    switch (b) {
        case BOSS_1_id:
            a.setProperty("主体", "1");
            check1(a);
            break;
        case BOSS_2_id:
            a.setProperty("手1", "1");
            check1(a);
            break;
        case BOSS_3_id:
            a.setProperty("手2", "1");
            check1(a);
            break;
        case BOSS_4_id:
            a.setProperty("手3", "1");
            check1(a);
            break;
        case BOSS_5_id:
            a.setProperty("手4", "1");
            check1(a);
            break;
        case BOSS_6_id:
            a.setProperty("手5", "1");
            check1(a);
            break;
        case BOSS_7_id:
            a.setProperty("手6", "1");
            check1(a);
            break;
        case BOSS_8_id:
            a.setProperty("手7", "1");
            check1(a);
            break;
        case BOSS_9_id:
            a.setProperty("手8", "1");
            check1(a);
            break
    }
}

function check1(m) {
    var a = m.getMapInstance(实例地图[0]);
    var b = parseInt(m.getProperty("主体"));
    var l = parseInt(m.getProperty("手1"));
    var k = parseInt(m.getProperty("手2"));
    var j = parseInt(m.getProperty("手3"));
    var g = parseInt(m.getProperty("手4"));
    var f = parseInt(m.getProperty("手5"));
    var e = parseInt(m.getProperty("手6"));
    var d = parseInt(m.getProperty("手7"));
    var c = parseInt(m.getProperty("手8"));
    if (b == 1 && l == 1 && k == 1 && j == 1 && g == 1 && f == 1 && e == 1 && d == 1 && c == 1) {
        a.getWeatherEffectNotice("扎昆被击败了，你们拯救了冰封雪域。", 265, 3000, 1);
        m.getPlayers().forEach(function (i) {
            i.getAPI().updateAchievement(646, 0, 1, 10);
            i.getAPI().updateAchievement(647, 0, 1, 100);
            i.getAPI().updateAchievement(648, 0, 1, 1000);
            i.getAPI().updateAchievement(649, 0, 1, 1000)
        });
        openNpc(m, 9130027, "评价系统");
        m.startEventTimer(退场倒计时 * 1000);
        for (var h = 0; h < m.getPlayerCount(); h++) {
            m.getPlayers().get(h).dropMessage(6, "[" + 副本名称 + "] 挑战成功！已召唤击杀奖励！！")
        }
    } else {
        player.dropMessage(-1, "一个部位被击溃了..")
    }
}

function 台阶可见() {
    em.schedule("台阶隐藏", 10 * 1000);
    em.getMapFactory().getMap(实例地图[0]).onSyncDynamicFoothold(["zdc1", "zdc2", "zdc3", "zdc4", "zdc5", "zdc6", "zdc7", "zdc8", "zdc9", "zdc10", "zdc11", "zdc12", "zdc13", "zdc14", "zdc15", "zdc16", "zdc17", "zdc18"], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [-464, -388, -310, -514, -439, -362, -512, -436, -358, 350, 426, 504, 384, 464, 546, 363, 439, 517], [-186, -187, -184, -102, -101, -99, -7, -5, -8, -189, -190, -187, -99, -102, -101, -7, -5, -8])
}

function 台阶隐藏() {
    em.schedule("台阶可见", 10 * 1000);
    em.getMapFactory().getMap(实例地图[0]).onSyncDynamicFoothold(["zdc1", "zdc2", "zdc3", "zdc4", "zdc5", "zdc6", "zdc7", "zdc8", "zdc9", "zdc10", "zdc11", "zdc12", "zdc13", "zdc14", "zdc15", "zdc16", "zdc17", "zdc18"], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-464, -388, -310, -514, -439, -362, -512, -436, -358, 350, 426, 504, 384, 464, 546, 363, 439, 517], [-186, -187, -184, -102, -101, -99, -7, -5, -8, -189, -190, -187, -99, -102, -101, -7, -5, -8])
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id || d == BOSS_2_id || d == BOSS_3_id || d == BOSS_4_id || d == BOSS_5_id || d == BOSS_6_id || d == BOSS_7_id || d == BOSS_8_id || d == BOSS_9_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPlayerKilled(b, a) {}

function onPartyDisbanded(a) {
    on玩家退场(a, player, false)
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onItemPickedUp(b, a, c) {};